//package com.blacktry.config;
//
//import org.springframework.http.HttpMethod;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//
//@EnableWebSecurity
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
//
//    //认证
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//        auth.inMemoryAuthentication()
//                .passwordEncoder(new BCryptPasswordEncoder())
//                .withUser("root").password(new BCryptPasswordEncoder().encode("123456")).roles("vip1","vip2","vip3")
//                .and()
//                .withUser("admin").password(new BCryptPasswordEncoder().encode("123456")).roles("vip1");
//    }
//
//    //授权
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        //首页所有人都能访问，level页面只有有权限的人才能访问
//        http.authorizeRequests()
//                .antMatchers("/").permitAll()
//                .antMatchers("/**").permitAll()
//                .antMatchers("/level1/**").hasRole("vip1")
//                .antMatchers("/level2/**").hasRole("vip2")
//                .antMatchers("/level3/**").hasRole("vip3")
//        //没有权限默认跳到登陆页，默认会重定向到/login
//        .antMatchers(HttpMethod.OPTIONS)//跨域请求会先进行一次options请求
//                .permitAll();
//        http.formLogin();
//
//    }
//}
